var bookData = dataOne().bookData;
// console.log(bookData)

$(function () {
    // 畅销书排行榜获取高度
    // var conH = $(".aside-left .top .con-wrap").height();
    // $(".aside-left .top .con").css("height", conH + "px");
    //
    // var rankH = $(".con li:nth-child(2) .book-rank").height();
    // var rankShowH = 3.5 * rankH;
    // var overHiddenH = rankH * 5 + rankShowH;
    // $(".book-show").css("height", rankShowH + "px");
    //
    // var curBookRank = $(".aside-left li.active .book-rank");
    // curBookRank.css("height", rankH + "px");

    //   畅销书数据获取
    var pressData = dataOne().bestSelling;
    var rankUl = $(".aside-left .top ul li");
    var Month = [
        "Jan",
        "Feb",
        "Mar",
        "Apr",
        "May",
        "Jun",
        "Jul",
        "Aug",
        "Sep",
        "Oct",
        "Nov",
        "Dec"
    ];
    var bookName = "";
    var pressName = "";
    var author = "";
    var ISBN = "";
    var pressDate = "";
    var pricing = "";
    var imageUrl = "";

    rankUl.each(function (index, item) {
        var len = item.children.length;
        $.ajax({
            type: "get",
            url: "screen/top",
            dataType: "json",
            success: function (data) {
                pressData = data;
                for (var i = 0; i < pressData.length; i++) {
                    bookName = pressData[i]["alias_name"];
                    pressName = pressData[i]["alias_name"];
                    author = pressData[i]["author"];
                    // ISBN = pressData[Month[index]][i]["ISBN"];
                    // pressDate = pressData[Month[index]][i]["pressDate"];
                    pricing = pressData[i]["pricing"];
                    imageUrl = pressData[i]["avatar"];
                    // console.log(imageUrl);
                    $(item.children[i])
                        .find(".name div img")
                        .attr("src", imageUrl);
                    // .text(imageUrl);
                    $(item.children[i])
                        .find(".company")
                        .text(pressName);
                    $(item.children[i])
                        .find(".ranking")
                        .text(i++);
                    $(item.children[i])
                        .find(".authors")
                        .text(author);
                    $(item.children[i])
                        .find(".isbn")
                        .text(ISBN);
                    $(item.children[i])
                        .find(".pub-date")
                        .text(pressDate);
                    $(item.children[i])
                        .find(".pricing")
                        .text(pricing);
                    $(item.children[i])
                        .find("img")
                        .attr("src", imageUrl);
                }
            }
        });

    });
    // // 复制第一个ul
    // var parentWrap = $(".aside-left .top .over-wrap");
    // var ulClone = $(".aside-left .top ul")
    //     .eq(0)
    //     .clone(true);
    // parentWrap.append(ulClone);
    //
    // //   添加点击事件
    // $(".aside-left .top").on('click', 'li', function (el) {
    //     var curItem = $(el.currentTarget);
    //     var bookName = curItem.find('.name').text().trim();
    //     var hasBook = false;
    //     var index = 0;
    //     console.log(bookName)
    //     for (var i = 0; i < bookData.length; i++) {
    //         console.log(bookData[i]["BookInformation"]["bookName"])
    //         if (bookData[i]["BookInformation"]["bookName"] === bookName) {
    //             index = i;
    //             hasBook = true;
    //             break;
    //         }
    //     }
    //
    //     if (!hasBook) return false;
    //
    //     var curHref = window.location.href;
    //     var str = curHref.indexOf("index.html");
    //     var newHref = curHref.substr(0, str) + "four.html?index=" + index;
    //     window.location.href = newHref;
    // })
    //
    // //   获取行高
    // var topSpan = $(".aside-left .top .book-rank span");
    // var topSpanH = topSpan.height();
    // topSpan.css("line-height", topSpanH + "px");
    //
    // var bottomSpan = $(".aside-left .bottom .book-rank span");
    // var bottomSpanH = bottomSpan.height();
    // bottomSpan.css("line-height", bottomSpanH + "px");
});
window.addEventListener('resize', function () {
    console.log('当前窗口宽度:', window.innerWidth);
});
console.log(window.innerWidth);
//   // 柱形折线图
$.ajax({
    url: '/screen/projectManth',
    type: 'get',
    dataType: 'json',
    success: function (data) {
        var trendBar1 = echarts.init(document.getElementById("trendBar1"));

        var optionBar = {
            grid: {
                top: 50,
                bottom: "20%"
            },
            legend: {
                data: ["月度销量"],
                right: "5%",
                itemWidth: 18,
                itemHeight: 12,
                textStyle: {
                    color: "#fff"
                }
            },
            xAxis: {
                data: [
                    "1月",
                    "2月",
                    "3月",
                    "4月",
                    "5月",
                    "6月",
                    "7月",
                    "8月",
                    "9月",
                    "10月",
                    "11月",
                    "12月"
                ],
                axisLine: {
                    show: false,
                    lineStyle: {
                        color: "#07bffb"
                    }
                },
                axisTick: {
                    show: false
                },
                axisLabel: {
                    interval: 0
                }
            },
            yAxis: [
                {
                    name: "月(/单)",
                    axisLine: {
                        show: false,
                        lineStyle: {
                            color: "#07bffb"
                        }
                    },
                    splitLine: {
                        show: false
                    },
                    axisTick: {
                        show: false
                    },
                    interval: 5,
                    min: 0,
                    max: 20,
                    position: "left"
                }
            ],
            series: [
                {
                    name: "月度销量",
                    type: "bar",
                    barWidth: "40%",
                    barGap: 5,
                    itemStyle: {
                        normal: {
                            color: new echarts.graphic.LinearGradient(
                                0,
                                0,
                                0,
                                1,
                                [
                                    {
                                        offset: 0,
                                        color: "#00fecc"
                                    },
                                    {
                                        offset: 0.8,
                                        color: "#2690cf"
                                    }
                                ],
                                false
                            )
                        }
                    },
                    data: data
                },
                // {
                //   name: "同比增长",
                //   type: "line",
                //   itemStyle: {
                //     color: "#fff"
                //   },
                //   yAxisIndex: 1,
                //   data: [10, 8, 36, 12, 24, 16, 48, 32, 18, 14, 66, 70]
                // }
            ]
        };
        trendBar1.setOption(optionBar);
    },
    error: function (xhr, status, error) {
        console.log(error);
    }
});

